// 转换函数
interface childrenTransform{
    value: number;
    label: string;
    children?: childrenTransform[];
}

interface TransformedDepartment {
    ID: number;
    ChnName: string;
    EngName: string;
    Phone: string;
    Email: string;
    children?: TransformedDepartment[];
    cntAdd : string;
    isUse : string;
}

export function transformJson(json: childrenTransform[]): childrenTransform[] {
    return json.map(item => {
        const transformedItem: childrenTransform = {
            value: item.departID,
            label: item.departChnName,
            children: item.children ? item.children.map(child => ({
                value: child.secondID,
                label: child.secondChnName
            })) : undefined
        };
        return transformedItem;
    });
}
export function transformDepartJson(json: TransformedDepartment[]): TransformedDepartment[] {
    return json.map(item => {
        const transformedItem: TransformedDepartment = {
            ID:  item.departID,
            ChnName: item.departChnName,
            EngName:item.departEngName,
            Phone: item.departPhone,
            Email: item.departEmail,
            cntAdd : item.cntAdd,
            isUse : item.isUse,
            children: item.children ? item.children.map(child => ({
                ID:  child.secondID,
                ChnName: child.secondChnName,
                EngName:child.secondEngName,
                Phone: child.secondPhone,
                Email: child.secondEmail,
                cntAdd : child.cntAdd,
                isUse : child.isUse,
            })) : undefined
        };
        return transformedItem;
    });
}

